﻿using System;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;

namespace lapinou_game2
{
    class Cursor
    {
        MouseState mouseState;
        ContentManager Content;
        Sprite cursor, pointer;
        Vector2 posCursor;

        int winWidth;
        int winHeight;

        public Cursor(ContentManager Content, int winWidth, int winHeight)
        {
            this.winWidth = winWidth;
            this.winHeight = winHeight;
            this.Content = Content;

            cursor = new Sprite(winWidth / 2, winHeight / 2);
            pointer = new Sprite(winWidth / 2, winHeight / 2);
        }

        public void Initialize()
        {
            posCursor = cursor.Position;
            
        }

        public void loadCursor()
        {
            cursor.LoadContent(Content, "image/cursor");
            //pointer.LoadContent(Content, "image/pointer");
        }

        public void moveCursor()
        {
            mouseState = Mouse.GetState();
            cursor.Position = new Vector2(mouseState.X, mouseState.Y);
            pointer.Position = new Vector2(mouseState.X, mouseState.Y);
            posCursor = cursor.Position;
        }

        public void moveCursorCoord(Vector2 posCur)
        {
            cursor.Position = new Vector2(posCur.X, posCur.Y);
            posCursor = cursor.Position;
        }

        public Vector2 getPos()
        {
            return posCursor;
        }


        public void drawCursor(SpriteBatch spriteBatch)
        {
            cursor.Draw(spriteBatch);
        }

        /*public void drawPointer(SpriteBatch spriteBatch)
        {
            pointer.Draw(spriteBatch);
        }*/

        public bool isRectangleOver(int x1, int y1, int x2, int y2)
        {
            return (mouseState.X >= x1 && mouseState.X <= x2 && mouseState.Y >= y1 && mouseState.Y <= y2);
        }

        public string buttonPressed()
        {
            if (mouseState.LeftButton == ButtonState.Pressed)
                return "left";
            else if (mouseState.RightButton == ButtonState.Pressed)
                return "right";
            else if (mouseState.MiddleButton == ButtonState.Pressed)
                return "middle";
            else
                return null;
        }
    }
}
